using System.Collections.Generic;
public class CreativeBackPack : StoreView
{
    public int page = 0;
    public List<Slot> CreativeSlots = new List<Slot>();
    public CreativeBackPack() : base()
    {
        base.Title = "CreativeBackPack";
    }
    public override void _Ready()
    {
        base._Ready();
    }
    public override void Create()
    {
        base.Create();
        int i = 0;
        for (int y = 0; y < 6; y++)
        {
            for (int x = 0; x < 9; x++)
            {
                Slot slot = CreateSlot(36 + y * 9 + x, 5 + x * 21, -127 + y * 21);
                slot.SetClick(OnClick);
                slot.HoldIn = CreativePlayerHoldIn;
                slot.SetShiftClick(OnShiftClick);
                if (Materials.GetItemMateria(i) != null)
                    slot.SetItemStack(Materials.GetItemMateria(i).GetItemStack());
                else slot.SetItemStack(null);
                CreativeSlots.Add(slot);
                i++;
            }
        }
    }
    public void CreativePlayerHoldIn(Slot slot)
    {
        if (HoldInEvent != null)
            HoldInEvent(slot);
        if (player != null)
        {
            ItemStack item = CreativeSlots[slot.index-36].itemStack;
            if (item != null)
            {
                player.view.ItemNameTag.Visible = true;
                player.view.ItemNameTag.Text = item.DispalyName;
                player.view.Lore.Text = item.GetLore();
            }
            else
            {
                player.view.ItemNameTag.Visible = false;
                player.view.Lore.Visible = false;
            }
        }
    }
    public void UpdataItmes()
    {
        int pass = 0;
        for (int i = 0; i < CreativeSlots.Count; i++)
        {
            Slot slot = CreativeSlots[i];
            ItemMateria im = Materials.GetItemMateria(page * 9 + i + pass);
            if (im != null)
            {
                if (!im.Hide)
                {
                    slot.SetItemStack(im.GetItemStack());
                }
                else
                {
                    pass++;
                }
            }
            else
            {
                slot.SetItemStack(null);
            }
        }
    }
    public virtual void Updata(Player player)
    {
        base.Updata(player);
        if (player != null)
        {

        }
    }
    public void OnClick(Slot slot)
    {
        if (slot.itemStack != null)
        {
            BlockWorld.player.store.CursourItem = slot.itemStack.Copy();
        }
        else
        {
            BlockWorld.player.store.CursourItem = null;
        }
    }
    public void OnShiftClick(Slot slot)
    {
        if (slot.itemStack != null)
        {
            BlockWorld.player.store.AddItem(slot.itemStack.Copy(64));
        }
    }

    public void PageDown()
    {
        page++;
        UpdataItmes();
    }
    public void PageUp()
    {
        page--;
        if (page < 0) page = 0;
        UpdataItmes();
    }
}
